<template>
  <el-dialog :title="title"
             :visible.sync="visible"
             v-loading="loading"
             :before-close="modalClose"
             :close-on-click-modal="false"
             :close-on-press-escape="false"
             width="50%"
             append-to-body>
    <el-form ref="formRef"
             :model="formModel"
             :rules="formRules"
             label-width="120px">
      <el-form-item label="知识点："
                    prop="knowledge">
        <el-input v-model="formModel.knowledge"
                  placeholder="请填写知识点"
                  type="textarea"></el-input>
      </el-form-item>
      <el-form-item label="关键词："
                    prop="keyWord">
        <el-input v-model="formModel.keyWord"
                  placeholder="请填写关键词"
                  type="textarea"></el-input>
      </el-form-item>

    </el-form>
    <p align="center">
      <el-button type="info"
                 @click="modalClose">取 消</el-button>
      <el-button type="primary"
                 @click="submitForm">新 增</el-button>
    </p>
  </el-dialog>
</template>
<script>
  export default {
    name: 'knowledgeDialog', // 知识点
    props: {
      knowledgeDataObj: {
        type: Object,
        default: {}
      },
      visible: {
        type: Boolean,
        default: false
      },
    },
    data () {
      return {
        title: '新增知识点',
        loading: false,
        formModel: {
          type: 1,
          knowledge: '', // 知识点
          keyWord: '', // 关键词
          isImportant: 0, // 是否是重点知识: 1:重点 0： 不是重点
        },
        formRules: {
          knowledge: [{ required: true, message: '请输入知识点', trigger: 'blur' }],
          keyWord: [{ required: true, message: '请输入知识点', trigger: 'blur' }]
        },

      }
    },
    methods: {
      modalClose () {
        this.$emit('update:visible', false); // 直接修改父组件的属性
      },
      submitForm () {
        this.$refs.formRef.validate((valid) => {
          if (valid) {
            this.$emit('childKnowledgeData', this.formModel);
            this.modalClose();
          }
        })
      },

    },
    created () {
      console.log(this.knowledgeDataObj)
    }
  }
</script>
<style scoped lang="scss">
</style>